<admintpl file="header" />
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:U('Adminsubject/subject_lists')}">专题列表</a></li>
        <li><a href="{:U('Adminsubject/edit_subject', ['id' => $subject_id])}">编辑专题</a></li>
        <li class="active"><a>编辑专题相关文章</a></li>
    </ul>
    <form class="well form-search" method="post" action="{:U('Adminsubject/edit_article', ['subject_id' => $subject_id])}">
        关键字：
        <input type="text" name="keyword" style="width: 200px;" value="{$formget.keyword|default=''}" placeholder="请输入关键字...">
        <input type="submit" class="btn btn-primary" value="搜索" />
        <a class="btn btn-danger" href="{:U('Adminsubject/edit_article', ['subject_id' => $subject_id])}">清空</a>
    </form>
        <php>
            $has_article_ids = explode(',', $subject['article_ids']);
        </php>
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="50">ID</th>
                <th>标题</th>
                <th width="150">创建时间</th>
                <th width="100">是否关联</th>
                <th width="70">操作</th>
            </tr>
            </thead>
            <foreach name="lists" item="vo">
                <tr>
                    <td>{$vo.id}</td>
                    <td>{$vo.post_title}</td>
                    <td>{:date('Y-m-d H:i:s', strtotime($vo['post_date']))}</td>
                    <td style="text-align: center">
                        <if condition="in_array($vo['id'], $has_article_ids)">
                            <span style="color: red;">是</span>
                        </if>
                        <if condition="!in_array($vo['id'], $has_article_ids)">
                            <span>否</span>
                        </if>
                    </td>
                    <td>
                        <if condition="in_array($vo['id'], $has_article_ids)">
                            <a class="delete_article" data-id="{$vo.id}">删除</a>
                        </if>
                        <if condition="!in_array($vo['id'], $has_article_ids)">
                            <a class="add_article" data-id="{$vo.id}">添加</a>
                        </if>
                    </td>
                </tr>
            </foreach>
        </table>
        <div class="pagination">{$page}</div>
    </form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script>
    $(document).ready(function () {
        $('body').delegate('.delete_article', 'click', function () {
            var article_id      = $(this).attr('data-id');
            var subject_id      = "{$subject['id']}";
            $.get("<?php echo U('Portal/Adminsubject/change_subject_article');?>", {subject_id : subject_id, article_id : article_id, type : 'del'}, function (data) {
                if (data.status) {
                    window.location.reload();
                }
            })
        });
        $('body').delegate('.add_article', 'click', function () {
            var article_id      = $(this).attr('data-id');
            var subject_id      = "{$subject['id']}";
            $.get("<?php echo U('Portal/Adminsubject/change_subject_article');?>", {subject_id : subject_id, article_id : article_id, type : 'add'}, function (data) {
                if (data.status) {
                    window.location.reload();
                }
            })
        });
    })
</script>
</body>
</html>